local function getupvaluetable(func, inname)
    local i = 1
    while true do
        local name, value = debug.getupvalue(func, i)
        if name == nil then
            return
        end
        
        if name == inname then
            return i,value
        end
        
        i=i+1
    end
end

local lua = _P.lua


--[[
local idx, old_func = getupvaluetable(lua.CMD.add_coins,'add_coins')
local _, reason = getupvaluetable(old_func,'reason')


local function add_coins(uid,data,coins,reason2,...)
    data.coins = data.coins + coins
    if reason2 == reason.BUY_FROM_SHOP_RMB then
        local ex_coins = ... or 0
        data.charge_count = data.charge_count + 1
        data.pay_money = (data.pay_money + coins) - ex_coins --减出加成的钱
        data.ex_money = data.ex_money + ex_coins
        local charge_data = {uid = uid,pay_money = data.pay_money,vip_level = data.vip_level,charge_count = data.charge_count,pay_coins = coins}
        R().exdbsvr(1):send(".event_mgr", "trigger", "on_coins_change",charge_data)
    end

    if reason2 == reason.BUY_FROM_SHOP_RMB then
        local extra_info = {ex_coins = ... or 0}
        billlog({op="addcoins",uid = uid,curr = data.coins,value = coins,r = reason2},extra_info)
    else
        billlog({op="addcoins",uid = uid,curr = data.coins,value = coins,r = reason2},...)
    end
    
    return true,{
        curr = data.coins,
        chged = coins,
    }
end

debug.setupvalue(lua.CMD.add_coins,idx,add_coins)
--]]



---------------------------------------data_worker---------------------------------------
-- python basesvr.py data_worker frame/hotfix/patch_base.lua 

print("__hotfix___data_worker________start")

local idx, sync_run_by_uid = getupvaluetable(lua.CMD.add_coins,'sync_run_by_uid')
-- print("_____sync_run_by_uid__________",idx, sync_run_by_uid, type(sync_run_by_uid))
-- local _, reason = getupvaluetable(old_func,'reason')
--今日输赢金（救援金用到
local function add_win_lose_coins(uid,data,coins)
    dbglog("__add_win_lose_coins",uid,coins)
    data.win_lose_today = (data.win_lose_today or 0) + coins
end

local function cmd_add_win_lose_coins(uid,...)
    dbglog("__cmd__add_win_lose_coins_____________")
    sync_run_by_uid(uid, add_win_lose_coins,...) 
end
--今日输赢金
lua.CMD.add_win_lose_coins = cmd_add_win_lose_coins




-- 累计投注
local function add_total_lose_coins(uid,data,coins)
    dbglog("add_total_lose_coins", coins)
    data.total_lose_coins = (data.total_lose_coins or 0) + coins
end


local function cmd_add_total_lose_coins(uid,...)
    dbglog("__cmd_add_total_lose_coins_____________")
    sync_run_by_uid(uid, add_total_lose_coins,...) 
end
--增加累计投注
lua.CMD.add_total_lose_coins = cmd_add_total_lose_coins

print("__hotfix___data_worker________end")
---------------------------------------data_worker---------------------------------------